package empox.pos.info;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

public class InfoListAdapter extends BaseAdapter {

	Context con;
	InfoHeadInfo[] ihi;
	boolean[] bl;

	public InfoListAdapter(Context mContext) {
		con = mContext;
	}

	public void setValue(InfoHeadInfo[] mInfoHeadInfo, boolean[] mBoolean) {
		ihi = mInfoHeadInfo;
		bl = mBoolean;
	}

	public int getCount() {
		if (ihi == null) {
			return 0;
		}
		return ihi.length;
	}

	public Object getItem(int arg0) {
		return arg0;
	}

	public long getItemId(int arg0) {
		return arg0;
	}

	static class SH {
		CheckBox cb;
		TextView tv1;
		TextView tv2;
		TextView tv3;
	}

	public View getView(int position, View convertView, ViewGroup arg2) {
		SH sh = new SH();

		if (convertView == null) {
			convertView = new LinearLayout(con);
			((LinearLayout) convertView).setGravity(Gravity.CENTER);

			sh.cb = new CheckBox(con);
			sh.cb.setWidth(100);
			sh.cb.setFocusable(false);
			sh.cb.setEnabled(false);
			((LinearLayout) convertView).addView(sh.cb);

			sh.tv1 = new TextView(con);
			sh.tv1.setWidth(200);
			sh.tv1.setGravity(Gravity.CENTER);
			((LinearLayout) convertView).addView(sh.tv1);
			sh.tv1.setTextColor(0xff57290a);

			sh.tv2 = new TextView(con);
			sh.tv2.setWidth(400);
			sh.tv2.setGravity(Gravity.CENTER);
			((LinearLayout) convertView).addView(sh.tv2);
			sh.tv2.setTextColor(0xff57290a);

			sh.tv3 = new TextView(con);
			sh.tv3.setWidth(100);
			sh.tv3.setGravity(Gravity.CENTER);
			((LinearLayout) convertView).addView(sh.tv3);
			sh.tv3.setTextColor(0xff57290a);

			convertView.setTag(sh);
		} else {
			sh = (SH) convertView.getTag();
		}

		sh.cb.setChecked(bl[position]);
		// sh.tv1.setText(ihi[position].billTime);
		sh.tv1.setText(ihi[position].showTime);
		sh.tv2.setText(ihi[position].brief);
		sh.tv3.setText(ihi[position].status);

		return convertView;
	}

}
